package cn.itcast.service.impl;

import cn.itcast.dao.AccountDao;
import cn.itcast.domain.Account;
import cn.itcast.entity.PageResult;
import cn.itcast.service.AccountService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("accountService")
public class AccountServiceImpl implements AccountService {

    @Autowired
    private AccountDao accountDao;

    public List<Account> findAll() {
        System.out.println("业务层：查询所有账户...");
        return accountDao.findAll();
    }

    public void saveAccount(Account account) {
        System.out.println("业务层：保存帐户...");
        accountDao.saveAccount(account);
    }

    @Override
    public Account findById(Integer id) {
        return accountDao.findById(id);
    }

    @Override
    public PageResult<Account> findPage(int page, int size) {
        PageHelper.startPage(page, size);
        Page<Account> pageResult = (Page<Account>) accountDao.findPage();
        return new PageResult<>(pageResult.getTotal(), pageResult.getResult());
    }

    @Override
    public void add(Account account) {
        accountDao.add(account);
    }

    @Override
    public void delete(Integer id) {
        accountDao.delete(id);
    }

    @Override
    public void updateAndDelete(Integer id) {
        accountDao.updateAndDelete(id);
    }

    @Override
    public void update(Account account) {
        accountDao.update(account);
    }


}
